// 转换时间
const getDate = (year, month, day, hour, minute) => {
  // debugger
  const newyear = year.substr(0, year.length - 1);
  const setmonth = month.substr(0, month.length - 1);
  // const newmonth = setmonth < 10 ? '0' + setmonth : setmonth;
  const newmonth = setmonth .toString().padStart(2,"0")

  const setday = day.substr(0, day.length - 1);
  const newday = setday < 10 ? '0' + setday : setday;

  const newhour = hour.length < 2 ? '0' + hour : hour;

  const newminute = minute.length < 2? '0' + minute : minute;
  var date=new Date()
  var ceshiYear=date.getFullYear()
  // debugger
  // var ceshiMonth=(date.getMonth()+1)>=10 ? date.getMonth()+1: "0"+(date.getMonth()+1)
  var ceshiMonth=(date.getMonth()+1).toString().padStart(2,"0")
  // var ceshiDay=date.getDate()>=10?date.getDate():'0'+date.getDate()
  var ceshiDay=date.getDate().toString().padStart(2,"0")
  var ceshiHour=date.getHours()>=10?date.getHours():'0'+date.getHours()
  var ceshiMin=date.getMinutes()>=10?date.getMinutes():'0'+date.getMinutes()
  var ceshi=ceshiYear+"-"+ceshiMonth+"-"+ceshiDay+" "+ceshiHour+":"+ceshiMin+":00"
//  console.log(ceshi)
  if(minute!=undefined &&hour!=undefined){
    // debugger
    if( year==''&& month==''&& day==''&&hour==''&&minute==''){
      return ceshi
    }else{
      return newyear + '-' + newmonth + '-' + newday + ' ' + newhour + ":" + newminute+":00";
    }
  }else{
    if( year==''&& month==''&& day==''){
      return ceshiYear+"-"+ceshiMonth+"-"+ceshiDay
    }else{
      return newyear + '-' + newmonth + '-' + newday + ' ';
    }
  }
}

// 将时间戳转换为时间
const getobjDate = (date)=> {
  let now;
  if (date){
     now = new Date(date)
  }else{
     now = new Date()
  }
    let y = now.getFullYear(),
    m = (now.getMonth() + 1).toString().padStart(2,"0"),
    d = now.getDate().toString().padStart(2,"0"),
    h = now.getHours().toString().padStart(2,"0"), //获取当前小时数(0-23)
    f = now.getMinutes().toString().padStart(2,"0"),

      n = (Math.ceil((now.getMinutes()) / 10))*10; //获取当前分钟数(0-59)  取整数
      // debugger
  return y + "-" +m + "-" + d + " " + h + ":" + f;

}

//根据年月  获取天数
const mGetDate = (year, month) => {
  var d = new Date(year, month, 0);
  return d.getDate();
}
//根据时间2019-01-02 09：12  得到 ['2019','1','2','9','12']
const getarrWithtime = (str) => {
  let arr = [];
  let arr1 = str.split(' ');
  let arr2 = (arr1[0]).split('-');
  let arr3 = arr1[1].split(':');
  arr = arr2.concat(arr3);
  // console.log(arr[3].length)
  // arr[1] = arr[1].startsWith('0') ? arr[1].substr(1, arr[1].length) : arr[1];
  arr[1]=arr[1].toString().padStart(2,"0")
  // arr[2] = arr[2].startsWith('0') ? arr[2].substr(1, arr[2].length) : arr[2];
  arr[2]=arr[2].toString().padStart(2,"0")
  if(arr[3]!=undefined&&arr[4]!=undefined){
    // arr[3]=arr[3].startsWith('0') || arr[3].length==2 ? arr[3] : "0"+arr[3]
    arr[3]=arr[3].toString().padStart(2,"0")
    // arr[4]=arr[4].startsWith('0') || arr[4].length==2 ? arr[4] : "0"+arr[4]
    arr[4]=arr[4].toString().padStart(2,"0")
  }
  return arr;
}
module.exports = {
  getDate,
  getobjDate,
  mGetDate,
  getarrWithtime,

}